package mx.vlabs.soapdroid.wsdl2java.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import mx.vlabs.soapdroid.wsdl2java.Wsdl2Java;

import org.eclipse.wb.swing.FocusTraversalOnArray;

import java.awt.Component;
import java.awt.GridLayout;

public class MainFrame extends JFrame {

	private JPanel contentPane;
	private JPanel pnlMain;
	private WizardPanel[] wizardPanels;
	private LoaderWindow loaderWindow;
	
	private Wsdl2Java wsdl2Java;


	/**
	 * Create the frame.
	 */
	public MainFrame() {
		
		
		wsdl2Java = new Wsdl2Java();
		
		pnlMain = new JPanel();
		
		wizardPanels = new WizardPanel[] {
				new WSDLSourcePanel(){{ setParentFrame(MainFrame.this); }},
				new WSClientGeneratorPanel(){{ setParentFrame(MainFrame.this); }}
		};
		
		setResizable(false);
		setTitle("WSDL2JAVA client generator for SOAP Droid");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 600, 400);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		NavigationPanel navigationPanel = new NavigationPanel(wizardPanels,this);
		contentPane.add(navigationPanel, BorderLayout.SOUTH);
		
		
		contentPane.add(pnlMain, BorderLayout.CENTER);
		pnlMain.setLayout(new GridLayout(1, 0, 0, 0));
		setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{contentPane}));
		
		UIUtils.centerWindow(this);
		loaderWindow = new LoaderWindow();
		UIUtils.centerWindow(loaderWindow);
		
	}

	public JPanel getPnlMain() {
		return pnlMain;
	}

	public Wsdl2Java getWsdl2Java() {
		return wsdl2Java;
	}
	
	public void openLoaderWindow(){
		UIUtils.centerWindow(loaderWindow,this.getBounds());
		openLoaderWindow("Loading...");
	}
	
	public void openLoaderWindow(String message){
		
		loaderWindow.setLoadingMessage(message);
		loaderWindow.setVisible(true);
	}
	
	public void closeLoaderWindow(){
		loaderWindow.setVisible(false);
	}

}
